<script>
$(function() {    
   $( "#grabar" )
    .button()
    .click(function() {
           // $dialog.dialog( "open" );
    });      
    
   $( "#crear" )
    .button()
    .click(function() {
           // $dialog.dialog( "open" );
    });    
    
   $( "#buscar" )
    .button()
    .click(function() {
           // $dialog.dialog( "open" );
    });  
    
    $("#filtro").change(function(){
        var codigo = $(this).val();
        //alert(codigo);
        $("#loadingImage").css("display", "block");
        var url = "<?=$this->config->item('base_url')?>/index.php/planes_cuenta/filtrar_planes/" + codigo;
        var datos = $(this).serialize(); 
        //alert(url)
        $.post(url, datos, function(resultado) {                              
          //alert(resultado);
          $('#listado-planes').html(resultado);  
          $("#loadingImage").css("display", "none");
        });          
    });
    
    
    var $tab_title_input = $("#tab_title");
    var $dialog_editar_plan = $( "#editarPlanForm" ).dialog({
                                autoOpen: false,
                                modal: true,
                                width: 700,                        
                                buttons: {
                                        Crear: function() {
                                            $("#poste_form", $dialog ).submit();
                                        },
                                        Cerrar: function() {
                                            $( this ).dialog( "close" );

                                        }
                                },
                                open: function() {
                                        $tab_title_input.focus();
                                },
                                close: function() {
                                    var url = "<?=$this->config->item('base_url')?>/index.php/planes_cuenta/index";
                                    location.href=url;   
                                }
                        });
                
    
    $("tr.editar_plan a").live("click",function(){
        //alert($(this).attr('id'));
        var this_url= $(this).attr("href");
        //alert(this_url);
        //alert($(this).attr('id'));

        if($(this).attr('id')=="editar"){
            $("#loadingImage").css("display", "block");
            $.post(this_url, { }, function(data){   
                //alert(data);
                $("div#editarPlanForm").html(data);
                $dialog_editar_plan.dialog( "open" );
                $("#loadingImage").css("display", "none");
            })  
        }
            


        return false;

    });     
            
});    
                
</script>

<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
?>
<br/>
<table border="0" width="100%">
    <tr>
        <td width="30%">
            <select id="filtro" nombre="filtro" class="ui-widget-content ui-corner-all" style="width:200px">
                <option value="0">Todos</option>
                <? foreach ($tipo_planes->result()  as $tipo_plan){  ?>
                    <option value="<?=$tipo_plan->id_subtipo_plan?>"><?=$tipo_plan->nm_subtipo_plan?></option>
                <? }?>
            </select>
        </td>
        <td width="10%" width="61%">
            <input type="text" name="" id=""  class="ui-widget-content ui-corner-all"/>
            
        </td>
        <td>
            <button id="buscar">Buscar</button>
        </td>
        <td width="60%" align="right">
            <button id="crear">Crear</button>
        </td>        
    </tr>
</table>

<table width="100%">
    <tr>
        <td width="100%">
            <div id="listado-planes" >
                <? $this->load->view('planes/listado_planes_ajax');?>   
            </div>
        </td>

    </tr>
</table>


<div id="editarPlanForm" title="Editar Plan Cuenta">

</div>
